<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        canvas {
            border: 2px solid;
        }
    </style>
</head>

<body>
    <canvas width="500" height="400" id="canvas"></canvas>



    <script>
        let canvas = document.getElementById('canvas');
        let pen = canvas.getContext('2d');
        pen.lineWidth = 5;
        pen.strokeStyle = 'orange';
        pen.fillStyle = 'skyblue';
        // pen.globalAlpha = 0.5;
        //---- 绘制矩形
        // pen.strokeRect(x, y, width, height);
        pen.strokeRect(100, 100, 250, 150);
        pen.fillRect(250, 50, 100, 100)

        pen.clearRect(0, 0, 500, 400);//清空矩形区域

        //----- 绘制弧形
        // arc(x, y, r, startAngle, endAngle, anticlockwise)
        // x、y：圆心坐标
        // r:半径
        //startAngle：开始落笔的弧度 0度的位置是3点钟方向
        //endAngle：结束的弧度, 弧度计算：Math.PI/180*角度
        //anticlockwise：可选，默认是false顺时针

        //半圆
        // pen.arc(250, 200, 100, 0, Math.PI / 180 * 180);
        // pen.closePath()
        // pen.fillStyle='red'
        // pen.fill()
        // pen.stroke();

        // 扇形
        pen.arc(250, 200, 100, Math.PI / 180 * 270, Math.PI / 180 * 330);
        pen.closePath()
        pen.stroke()


    </script>
</body>

</html>